package com.ytzl.itrip.controller;

import com.ytzl.itrip.common.DtoUtil;
import com.ytzl.itrip.common.EmptyUtils;
import com.ytzl.itrip.common.ErrorCode;
import com.ytzl.itrip.dto.Dto;
import com.ytzl.itrip.pojo.ItripAreaDic;
import com.ytzl.itrip.pojo.ItripLabelDic;
import com.ytzl.itrip.vo.ItripAreaDicVO;
import com.ytzl.itrip.vo.ItripLabelDicVO;
import com.ytzl.itrip.vo.ItripTokenVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by sam on 2018/2/10.
 */
@Controller
@Api(tags = "酒店模块业务")
@RequestMapping("/api/hotel")
public class HotelController extends BaseController {

    @ApiOperation(value = "查询酒店特色列表", httpMethod = "GET", response = Dto.class, produces = "application/json", notes = "获取酒店特色(用于查询页列表)" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码: </p>" +
            "<p>10205: 系统异常,获取失败</p>")
    @RequestMapping(value = "/queryhotelfeature", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto queryHotelFeature() {
        Map<String, Object> param = new HashMap();
        param.put("parentId", 16);
        try {
            List<ItripLabelDic> itripLabelDicList = itripLabelDicService.getItripLabelDicListByMap(param);
            List<ItripLabelDicVO> itripLabelDicVOList = new ArrayList<>();
            for (ItripLabelDic itripLabelDic : itripLabelDicList) {
                ItripLabelDicVO itripLabelDicVO = new ItripLabelDicVO();
                BeanUtils.copyProperties(itripLabelDic, itripLabelDicVO);
                itripLabelDicVOList.add(itripLabelDicVO);
            }
            return DtoUtil.returnDataSuccess(itripLabelDicVOList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DtoUtil.returnFail("系统异常,获取失败", ErrorCode.BIZ_QUERY_HOTEL_FEATURE_FAILED);
    }

    @ApiOperation(value = "查询商圈", httpMethod = "GET",
            protocols = "HTTP", produces = "application/json",
            response = Dto.class, notes = "根据城市查询商圈" +
            "<p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p>" +
            "<p>错误码：</p>" +
            "<p>10203 : cityId不能为空 </p>" +
            "<p>10204 : 系统异常,获取失败</p>")
    @RequestMapping(value = "/querytradearea/{cityId}", produces = "application/json", method = RequestMethod.GET)
    @ResponseBody
    public Dto queryTradeArea(@PathVariable @ApiParam(value = "cityId", name = "城市Id") Long cityId) {
        if (EmptyUtils.isEmpty(cityId))
            return DtoUtil.returnFail("cityId不能为空", ErrorCode.BIZ_QUERY_TRADE_AREA_IS_NOT_CITYID);
        Map<String, Object> param = new HashMap();
        param.put("isTradingArea", 1);
        param.put("parent", cityId);
        try {
            List<ItripAreaDic> itripAreaDicList = itripAreaDicService.getItripAreaDicListByMap(param);
            List<ItripAreaDicVO> itripAreaDicVOList = new ArrayList<>();
            for (ItripAreaDic itripAreaDic : itripAreaDicList) {
                ItripAreaDicVO itripAreaDicVO = new ItripAreaDicVO();
                BeanUtils.copyProperties(itripAreaDic, itripAreaDicVO);
                itripAreaDicVOList.add(itripAreaDicVO);
            }
            return DtoUtil.returnDataSuccess(itripAreaDicVOList);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return DtoUtil.returnFail("查询商业圈失败", ErrorCode.BIZ_QUERY_TRADE_AREA_FAILED);
    }

    @ApiOperation(value = "查询热门城市", httpMethod = "GET", response = Dto.class, produces = "application/json", notes = "查询国内、国外的热门城市(1:国内 2:国外)</br>" +
            "            <p>成功：success = ‘true’ | 失败：success = ‘false’ 并返回错误码，如下：</p></br>" +
            "            <p>错误码：</p></br>" +
            "            <p>10201 : type不能为空 </p></br>" +
            "            <p>10202 : 系统异常,获取失败</p>")
    @RequestMapping(value = "queryhotcity/{type}", method = RequestMethod.GET, produces = "application/json")
    @ResponseBody
    public Dto queryHotcity(@PathVariable int type) {
        List<ItripAreaDic> itripAreaDics = null;
        List<ItripAreaDicVO> itripAreaDicVOList = null;
        try {
            if (EmptyUtils.isNotEmpty(type)) {
                Map<String, Object> param = new HashMap<>();
                param.put("isHot", 1);
                param.put("isChina", type);
                itripAreaDics = itripAreaDicService.getItripAreaDicListByMap(param);
                if (EmptyUtils.isNotEmpty(itripAreaDics)) {
                    itripAreaDicVOList = new ArrayList<>();
                    for (ItripAreaDic itripAreaDic : itripAreaDics) {
                        ItripAreaDicVO itripAreaDicVO = new ItripAreaDicVO();
                        BeanUtils.copyProperties(itripAreaDic, itripAreaDicVO);
                        itripAreaDicVOList.add(itripAreaDicVO);
                    }
                }
            } else {
                return DtoUtil.returnFail("type不能为空", ErrorCode.BIZ_QUERY_HOTCITY_TYPE_IS_NOT_NULL);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return DtoUtil.returnFail("系统异常，获取失败", ErrorCode.BIZ_QUERY_HOTCITY_SYSTEM_ERROR);
        }
        return DtoUtil.returnDataSuccess(itripAreaDicVOList);
    }


}
